home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Table / Sources / Scroller.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.4 KB  |  167 lines  |  [TEXT/CWIE]

  1. //========================================================================================
  2. //
  3. //    File:                Scroller.cpp
  4. //    Release Version:    $ ODF 2 $  
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef SCROLLER_H
  11. #include "Scroller.h"
  12. #endif
  13.  
  14. #ifndef CONTENT_H
  15. #include "Content.h"
  16. #endif
  17.  
  18. #ifndef FRAME_H
  19. #include "Frame.h"
  20. #endif
  21.  
  22. //========================================================================================
  23. // CLASS FW_CScrollBarScroller
  24. //========================================================================================
  25.  
  26. FW_DEFINE_AUTO(CTableScroller)
  27. FW_DEFINE_CLASS_M1(CTableScroller, FW_CScrollBarScroller)
  28.  
  29. const FW_ClassTypeConstant FW_LTableScroller = FW_TYPE_CONSTANT('t','b','s','c');
  30. FW_REGISTER_ARCHIVABLE_CLASS(FW_LTableScroller, CTableScroller, CTableScroller::Create, FW_CScroller::Read, CTableScroller::Destroy, FW_CScroller::Write)
  31.  
  32. //----------------------------------------------------------------------------------------
  33. //    CTableScroller::CTableScroller
  34. //----------------------------------------------------------------------------------------
  35.  
  36. CTableScroller::CTableScroller(Environment* ev) :
  37.     FW_CScrollBarScroller(ev),
  38.     fTableFrame(NULL),
  39.     fTableContent(NULL)
  40. {
  41. FW_UNUSED(ev);
  42.     
  43.     FW_END_CONSTRUCTOR
  44. }
  45.  
  46. //----------------------------------------------------------------------------------------
  47. //    CTableScroller::~CTableScroller
  48. //----------------------------------------------------------------------------------------
  49.  
  50. CTableScroller::~CTableScroller()
  51. {
  52.     FW_START_DESTRUCTOR
  53. }
  54.  
  55. //----------------------------------------------------------------------------------------
  56. // CTableScroller::TranslationToPixels
  57. //----------------------------------------------------------------------------------------
  58.  
  59. FW_CPoint CTableScroller::TranslationToPixels(Environment* ev, const FW_CPoint& translation) const
  60. {
  61. FW_UNUSED(ev);
  62.     FW_CPoint pixelOffset(fTableContent->FindLeft(FW_FixedToInt(translation.x)) - kPenWidth, 
  63.                           fTableContent->FindTop(FW_FixedToInt(translation.y))  - kPenHeight);
  64.     return pixelOffset;
  65. }
  66.  
  67. //----------------------------------------------------------------------------------------
  68. // CTableScroller::PixelsToTranslation
  69. //----------------------------------------------------------------------------------------
  70.  
  71. FW_CPoint CTableScroller::PixelsToTranslation(const FW_CPoint& pixelOffset) const
  72. {
  73.     CCell cell;
  74.     fTableContent->FindCell(pixelOffset, cell);
  75.  
  76.     FW_CPoint offset(FW_IntToFixed(cell.fX), FW_IntToFixed(cell.fY));
  77.     return offset;
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //    CTableScroller::InitializeFromStream
  82. //----------------------------------------------------------------------------------------
  83.  
  84. void CTableScroller::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
  85. {
  86.     FW_CScrollBarScroller::InitializeFromStream(ev, stream);
  87.     
  88.     fTableFrame = (CTableFrame*)fFrame;
  89.     fTableContent = fTableFrame->GetTableContent(ev);
  90. }
  91.  
  92. //----------------------------------------------------------------------------------------
  93. // CTableScroller::GetScrollingArea
  94. //----------------------------------------------------------------------------------------
  95.  
  96. FW_CRect CTableScroller::GetScrollingArea(Environment* ev) const
  97. {    
  98.     FW_CRect bounds = fFrame->GetContentView(ev)->GetBoundsInContent(ev);
  99.     
  100.     FW_CRect scrollingBounds;
  101.     scrollingBounds[FW_kTopLeft] = PixelsToTranslation(bounds[FW_kTopLeft]);
  102.     scrollingBounds[FW_kBotRight] = PixelsToTranslation(bounds[FW_kBotRight]);
  103.  
  104.     FW_CPoint extent = fTableContent->GetExtent();
  105.     
  106.     if (bounds.right > extent.x)
  107.         scrollingBounds.right += FW_kFixedPos1;    
  108.     if (bounds.bottom > extent.y)
  109.         scrollingBounds.bottom += FW_kFixedPos1;    
  110.         
  111.     return scrollingBounds;
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. // CTableScroller::CalcMaxTranslation
  116. //----------------------------------------------------------------------------------------
  117.  
  118. FW_Fixed CTableScroller::CalcMaxTranslation(Environment* ev, FW_Fixed scrollingArea, FW_XYSelector direction)
  119. {
  120. FW_UNUSED(scrollingArea);
  121.     FW_CRect bounds = fFrame->GetContentView(ev)->GetBoundsInContent(ev);
  122.     FW_CPoint extent = fTableContent->GetExtent();
  123.  
  124.     FW_Fixed pixelMax = extent[direction] - bounds.Length(direction);
  125.     if (pixelMax < FW_kFixed0)
  126.         return FW_kFixed0;
  127.         
  128.     CCell maxCell = fTableContent->GetMaxRowCol();
  129.     
  130.     short max = direction == FW_kHorizontal ? maxCell.fX : maxCell.fY;
  131.     
  132.     short c = 0;
  133.     FW_Fixed pos = FW_kFixed0;
  134.     while (pos < pixelMax && c <= max)
  135.     {
  136.         pos += fTableContent->GetCellSize(c, direction);
  137.         c++;
  138.     }
  139.         
  140.     return FW_IntToFixed(c);
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. //    CTableScroller::Create
  145. //----------------------------------------------------------------------------------------
  146.  
  147. void* CTableScroller::Create(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  148. {
  149. FW_UNUSED(stream);
  150. FW_UNUSED(type);
  151.     FW_SOMEnvironment ev;
  152.     return FW_NEW(CTableScroller, (ev));
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    CTableScroller::Destroy
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void CTableScroller::Destroy(void* object, FW_ClassTypeConstant type)
  160. {
  161. FW_UNUSED(type);
  162.     CTableScroller* self = (CTableScroller*) object;
  163.     delete self;
  164. }
  165.  
  166.  
  167.